#ifndef __GUI_CMD_H__
#define __GUI_CMD_H__
#include <cstdint>
#include <cstdbool>

#define GUI_UART_BaudRate			115200	//波特率
#define GUI_UART_WordLength		    0		//数据长度 默认0就是8位
#define GUI_UART_StopBits			0		//停止位 默认0就是1位
#define GUI_UART_Parity				0		//校验位 0位无 1为偶校验 2为奇校验

#define GUI_START				    0x2355
#define GUI_STOP					0x0D0A

#define GUI_START0				    (uint8_t)(((GUI_START&0xFFFF)>>8)&0xFF)
#define GUI_START1				    (uint8_t)(((GUI_START&0xFFFF)>>0)&0xFF)

#define GUI_STOP0				    (uint8_t)(((GUI_STOP&0xFFFF)>>8)&0xFF)
#define GUI_STOP1				    (uint8_t)(((GUI_STOP&0xFFFF)>>0)&0xFF)

#define GUI_ADDR              		0x5207

#define GUI_ADDR0					(uint8_t)(((GUI_ADDR&0xFFFF)>>8)&0xFF)
#define GUI_ADDR1					(uint8_t)(((GUI_ADDR&0xFFFF)>>0)&0xFF)

#define GUI_COM_Error       0xFF
#define GUI_COM_Broadcast   0x00  //发送广播命令 检测是否有设备响应
#define GUI_COM_Chart 0x01
/*
BCNT 数据长度 表示从ADDR字节的后一字节开始 到校验码的前一字节为止 数据的长度 也是命令位+数据位的长度
BCNT=len(COM+DATA[])
CHK 检验码 表示校验码前所有字节之和
CHK=START0+START1+BCNT0+BCNT1+ADDR0+ADDR1+COM+DATA[]
*/
#pragma pack(1)
typedef struct 
{
	uint8_t START[2];
	uint8_t BCNT[2];
	uint8_t ADDR[2];
	uint8_t COM;
	uint8_t DATA[25];
	uint8_t CHK[2];
    uint8_t STOP[2];
	bool Flag;	//校验数据是否正确的标志 解析数据时正确则有效 发送数据时无关
}GUI_Struct;
#pragma pack()
//数据字节为小端格式 其他为大端格式

GUI_Struct Trans_GUI_to_Struct(uint8_t * buf);
uint8_t Trans_GUI_to_Buf(GUI_Struct GUI_Stu,uint8_t * buf);
uint8_t GUI_Slave_Send(GUI_Struct GUI_Stu);

extern bool GUI_COM_Thread_Flag;
extern uint8_t GUI_RxBit;
extern uint8_t GUI_RxBuffer[256];
extern uint8_t GUI_RxFlag;

extern uint8_t GUI_Status;
extern uint16_t GUI_Data_Len;

extern uint8_t GUI_Timer_Flag;
extern uint8_t GUI_Executing_Flag;  	//命令执行Flag

void Init_GUI(void);
uint8_t GUI_Judge(void);
void GUI_RX_Callback(uint8_t RX);
void GUI_Timer_Callback(void);
void GUI_Delay_Judge(uint16_t ms);
uint8_t GUI_Error_Executing(void);
void GUI_COM_Executing(GUI_Struct GUI_Stu);

#endif
